package com.pro.controller;

import com.pro.pojo.*;
import com.pro.service.ToExamineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author 谭金诚
 * @Description TODO
 * @Date 2022/1/14 17:04
 * @Version 1.0
 */
@Controller
@RequestMapping("/toExamine")
public class ToExamineController {

    @Autowired
    private ToExamineService service;

    /**
     * @ClassName getMicrocircleNums
     * @Author 谭金诚
     * @Date 2022/1/15
     * @Return map集合
     * 查询不同状态的审核微圈数
     */
    @RequestMapping("/getMicrocircleNums")
    @ResponseBody
    public JsonData getMicrocircleNums(){
        Map<String, Integer> microcircleNums = service.getMicrocircleNums();
        return microcircleNums.size() > 0 ? JsonData.buildSuccess(microcircleNums) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getAllMicroCircle
     * @Author 谭金诚
     * @Date 2022/1/15
     * @Return JsMicrocircle
     * 查询审核微圈信息
     */
    @RequestMapping("/getAllMicroCircle")
    @ResponseBody
    public JsonData getAllMicroCircle(JsMicrocircle jsMicrocircle){
        List<JsMicrocircle> allMicroCircle = service.getAllMicroCircle(jsMicrocircle);
        return allMicroCircle != null ? JsonData.buildSuccess(allMicroCircle) : JsonData.buildError("服务器错误");
    }

    /**
     * @ClassName getToExamineMicroCircleById
     * @Author 谭金诚
     * @Date 2022/1/15
     * @Return JsMicrocircle
     * //根据微圈id查询对应审核微圈信息
     */
    @RequestMapping("/getToExamineMicroCircleById")
    @ResponseBody
    public JsonData getToExamineMicroCircleById(JsMicrocircle jsMicrocircle){
        JsMicrocircle toExamineMicroCircleById = service.getToExamineMicroCircleById(jsMicrocircle);
        return toExamineMicroCircleById != null ? JsonData.buildSuccess(toExamineMicroCircleById) : JsonData.buildError("服务器错误");
    }

    /**
     * @ClassName updateCourseRecord
     * @Author 谭金诚
     * @Date 2022/1/15
     * @Return boolean
     * 审核微圈
     */
    @RequestMapping("/updateCourseRecord")
    @ResponseBody
    public JsonData updateCourseRecord(JsCourseRecord courseRecord){
        boolean flag = service.updateCourseRecord(courseRecord);
        return flag != false ? JsonData.buildSuccess(flag) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName addAuditLog
     * @Author 谭金诚
     * @Date 2022/1/17
     * @Return JsAuditLog
     * 添加微圈审核日志
     */
    @RequestMapping("/addAuditLog")
    @ResponseBody
    public JsonData addAuditLog(JsAuditLog jsAuditLog){
        boolean flag = service.addAuditLog(jsAuditLog);
        return flag != false ? JsonData.buildSuccess(flag) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getProductNums
     * @Author 谭金诚
     * @Date 2022/1/19
     * @Return map集合
     * 查询商品审核数目
     */
    @RequestMapping("/getProductNums")
    @ResponseBody
    public JsonData getProductNums(){
        Map<String, Integer> productNums = service.getProductNums();
        return productNums.size() > 0 ? JsonData.buildSuccess(productNums) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getAllProduct
     * @Author 谭金诚
     * @Date 2022/1/19
     * @Return List<Product>
     * 查询审核商品信息
     */
    @RequestMapping("/getAllProduct")
    @ResponseBody
    public JsonData getAllProduct(Product product){
        List<Product> allProduct = service.getAllProduct(product);
        return allProduct != null ? JsonData.buildSuccess(allProduct) : JsonData.buildError("服务端错误");
    }
    /**
     * @ClassName getToExamineProductById
     * @Author 谭金诚
     * @Date 2022/1/19
     * @Return Product
     * 根据商品id查询对应商品审核信息
     */
    @RequestMapping("/getToExamineProductById")
    @ResponseBody
    public JsonData getToExamineProductById(Product product){
        Product toExamineProductById = service.getToExamineProductById(product);
        return toExamineProductById != null ? JsonData.buildSuccess(toExamineProductById) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName updateProductCourseRecord
     * @Author 谭金诚
     * @Date 2022/1/19
     * @Return boolean
     * 审核商品
     */
    @RequestMapping("/updateProductCourseRecord")
    @ResponseBody
    public JsonData updateProductCourseRecord(JsCourseRecord courseRecord){
        System.err.println(courseRecord);
        boolean flag = service.updateProductCourseRecord(courseRecord);
        return flag != false ? JsonData.buildSuccess(flag) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName updateProductCourseRecord
     * @Author 谭金诚
     * @Date 2022/1/19
     * @Return List<ProductCategroy>
     * 高级检索——商品分类
     */
    @RequestMapping("/getProductCategroys")
    @ResponseBody
    public JsonData getProductCategroys(){
        List<ProductCategroy> productClass = service.getProductClass();
        return productCategroysSun(productClass) != null?JsonData.buildSuccess(productCategroysSun(productClass)):JsonData.buildError("服务器错误");
    }

    private List<ProductCategroy> productCategroysSun(List<ProductCategroy> productCategroys){
        for (int i = 0; i<productCategroys.size();i++ ){
            for (int k = 1; k<productCategroys.size();k++ ){
                if(productCategroys.get(i).getCategroyId() == productCategroys.get(k).getParentId()){
                    productCategroys.remove(productCategroys.get(i));
                    productCategroysSun( productCategroys);
                }
            }
        }
        return productCategroys;
    }

    /**
     * @ClassName getSeniorProduct
     * @Author 谭金诚
     * @Date 2022/1/19
     * @Return List<Product>
     * 高级检索——商品
     */
    @RequestMapping("/getSeniorProduct")
    @ResponseBody
    public JsonData getSeniorProduct(Product product){
        List<Product> seniorProduct = service.getSeniorProduct(product);
        return seniorProduct != null ? JsonData.buildSuccess(seniorProduct) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getCourseNums
     * @Author 谭金诚
     * @Date 2022/1/20
     * @Return map集合
     * 查询审核课程数
     */
    @RequestMapping("/getCourseNums")
    @ResponseBody
    public JsonData getCourseNums(Product product){
        Map<String, Integer> courseNums = service.getCourseNums();
        return courseNums.size() > 0 ? JsonData.buildSuccess(courseNums) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getAllCourse
     * @Author 谭金诚
     * @Date 2022/1/20
     * @Return List<JsCoursePlus>
     * 查询审核课程
     */
    @RequestMapping("/getAllCourse")
    @ResponseBody
    public JsonData getAllCourse(JsCoursePlus jsCoursePlus){
        List<JsCoursePlus> allCourse = service.getAllCourse(jsCoursePlus);
        return allCourse != null ? JsonData.buildSuccess(allCourse) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getToExamineCourseById
     * @Author 谭金诚
     * @Date 2022/1/20
     * @Return JsCoursePlus
     * 根据课程id查询对应审核课程信息
     */
    @RequestMapping("/getToExamineCourseById")
    @ResponseBody
    public JsonData getToExamineCourseById(Integer courseId){
        JsCoursePlus toExamineCourseById = service.getToExamineCourseById(courseId);
        return toExamineCourseById != null ? JsonData.buildSuccess(toExamineCourseById) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName updateCourseCourseRecord
     * @Author 谭金诚
     * @Date 2022/1/20
     * @Return boolean
     * 审核课程
     */
    @RequestMapping("/updateCourseCourseRecord")
    @ResponseBody
    public JsonData updateCourseCourseRecord(JsCourseRecord courseRecord){
        boolean flag = service.updateCourseCourseRecord(courseRecord);
        return flag != false ? JsonData.buildSuccess(flag) : JsonData.buildError("服务端错误");
    }

    /**
     * @ClassName getAllAuditLog
     * @Author 谭金诚
     * @Date 2022/1/21
     * @Return List<JsAuditLog>
     * 查询审核日志信息
     */
    @RequestMapping("/getAllAuditLog")
    @ResponseBody
    public JsonData getAllAuditLog(JsAuditLog jsAuditLog){
        List<JsAuditLog> allAuditLog = service.getAllAuditLog(jsAuditLog);
        return allAuditLog != null ? JsonData.buildSuccess(allAuditLog) : JsonData.buildError("服务端错误");
    }



}
